<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户昵称" prop="nickName">
        <el-input v-model="queryParams.nickName" placeholder="请输入用户昵称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="用户邮箱" prop="email">
        <el-input v-model="queryParams.email" placeholder="请输入用户邮箱" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="头像地址" prop="avatar">
        <el-input
          v-model="queryParams.avatar"
          placeholder="请输入头像地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="创建时间">
        <el-date-picker
          v-model="daterangeCreateTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="生日">
        <el-date-picker
          v-model="daterangeBrith"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="身高(cm)" prop="height">
        <el-input
          v-model="queryParams.height"
          placeholder="请输入身高(cm)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="体重(kg)" prop="weight">
        <el-input
          v-model="queryParams.weight"
          placeholder="请输入体重(kg)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="职业" prop="occupation">
        <el-input v-model="queryParams.occupation" placeholder="请输入职业" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="城市" prop="city">
        <el-input
          v-model="queryParams.city"
          placeholder="请输入城市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="城市编码" prop="cityCode">
        <el-input
          v-model="queryParams.cityCode"
          placeholder="请输入城市编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="审核状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择审核状态" clearable>
          <el-option v-for="dict in dict.type.user_update_check_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="邀请人id" prop="inviterId">
        <el-input v-model="queryParams.inviterId" placeholder="请输入邀请人id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="邀请树" prop="inviterTree">
        <el-input v-model="queryParams.inviterTree" placeholder="请输入邀请树" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="树层级" prop="treeLevel">
        <el-input v-model="queryParams.treeLevel" placeholder="请输入树层级" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="最上级id" prop="topInviterId">
        <el-input v-model="queryParams.topInviterId" placeholder="请输入最上级id" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['wxuser:updateUser:add']"
        >新增</el-button>
      </el-col> 
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['wxuser:updateUser:edit']">审核</el-button>
      </el-col>-->
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['wxuser:updateUser:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['wxuser:updateUser:export']">导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="updateUserList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" /> -->
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="用户昵称" align="center" prop="nickName" />
      <el-table-column label="用户邮箱" align="center" prop="email" />
      <!-- <el-table-column label="头像地址" align="center" prop="avatar" /> -->
      <el-table-column label="头像地址" align="center" prop="avatar">
        <template slot-scope="scope">
          <image-preview :src="scope.row.avatar" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="生日" align="center" prop="brith" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.brith, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="身高(cm)" align="center" prop="height" />
      <el-table-column label="体重(kg)" align="center" prop="weight" />
      <el-table-column label="职业" align="center" prop="occupation" />
      <el-table-column label="城市" align="center" prop="city" />
      <el-table-column label="城市编码" align="center" prop="cityCode" />
      <el-table-column label="审核状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.user_update_check_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="邀请人id" align="center" prop="inviterId" />
      <el-table-column label="邀请树" align="center" prop="inviterTree" />
      <el-table-column label="树层级" align="center" prop="treeLevel" />
      <el-table-column label="最上级id" align="center" prop="topInviterId" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status === '待审核'" plain size="mini" type="text" icon="el-icon-success" @click="handleUpdate(scope.row, '已通过')"
            v-hasPermi="['personal:photo:edit']">通 过</el-button>
          <el-button v-if="scope.row.status === '待审核'" plain size="mini" type="text" icon="el-icon-error" @click="handleUpdate(scope.row, '未通过')"
            v-hasPermi="['personal:photo:edit']">驳 回</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改更新审核对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户昵称" prop="nickName">
          <el-input v-model="form.nickName" placeholder="" readonly />
        </el-form-item>
        <el-form-item label="用户邮箱" prop="email">
          <el-input v-model="form.email" placeholder="" readonly />
        </el-form-item>
        <el-form-item label="头像地址" prop="avatar">
          <el-input v-model="form.avatar" placeholder="" readonly />
        </el-form-item>

        <el-form-item label="生日" prop="brith">
          <el-date-picker clearable v-model="form.brith" type="date" value-format="yyyy-MM-dd" placeholder="" readonly>
          </el-date-picker>
        </el-form-item>
        <el-form-item label="身高(cm)" prop="height">
          <el-input v-model="form.height" placeholder="" readonly />
        </el-form-item>
        <el-form-item label="体重(kg)" prop="weight">
          <el-input v-model="form.weight" placeholder="" readonly />
        </el-form-item>
        <el-form-item label="职业" prop="occupation">
          <el-input v-model="form.occupation" placeholder="" readonly />
        </el-form-item>
        <el-form-item label="城市" prop="city">
          <el-input v-model="form.city" placeholder="" readonly />
        </el-form-item>
        <el-form-item label="城市编码" prop="cityCode">
          <el-input v-model="form.cityCode" placeholder="" readonly />
        </el-form-item>
        <el-form-item label="审核状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择审核状态">
            <el-option v-for="dict in dict.type.user_update_check_status" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="邀请人id" prop="inviterId">
          <el-input v-model="form.inviterId" placeholder="请输入邀请人id" />
        </el-form-item>
        <el-form-item label="邀请树" prop="inviterTree">
          <el-input v-model="form.inviterTree" placeholder="请输入邀请树" />
        </el-form-item>
        <el-form-item label="树层级" prop="treeLevel">
          <el-input v-model="form.treeLevel" placeholder="请输入树层级" />
        </el-form-item>
        <el-form-item label="最上级id" prop="topInviterId">
          <el-input v-model="form.topInviterId" placeholder="请输入最上级id" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listUpdateUser, getUpdateUser, delUpdateUser, addUpdateUser, updateUpdateUser } from "@/api/wxuser/updateUser";

export default {
  name: "UpdateUser",
  dicts: ['user_update_check_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 更新审核表格数据
      updateUserList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 最上级id时间范围
      daterangeCreateTime: [],
      // 最上级id时间范围
      daterangeBrith: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nickName: null,
        email: null,
        avatar: null,
        createTime: null,
        brith: null,
        height: null,
        weight: null,
        occupation: null,
        city: null,
        cityCode: null,
        status: null,
        inviterId: null,
        inviterTree: null,
        treeLevel: null,
        topInviterId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // nickName: [
        //   { required: true, message: "用户昵称不能为空", trigger: "blur" }
        // ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询更新审核列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      if (null != this.daterangeBrith && '' != this.daterangeBrith) {
        this.queryParams.params["beginBrith"] = this.daterangeBrith[0];
        this.queryParams.params["endBrith"] = this.daterangeBrith[1];
      }
      listUpdateUser(this.queryParams).then(response => {
        this.updateUserList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        nickName: null,
        email: null,
        avatar: null,
        createTime: null,
        brith: null,
        height: null,
        weight: null,
        occupation: null,
        city: null,
        cityCode: null,
        status: null,
        inviterId: null,
        inviterTree: null,
        treeLevel: null,
        topInviterId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.daterangeBrith = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加更新审核";
    },
    /** 修改按钮操作 */
    handleUpdate(row, status) {
      // this.reset();
      const id = row.id || this.ids
      // getUpdateUser(id).then(response => {
      //   this.form = response.data;
      //   this.open = true;
      //   this.title = "修改更新审核";
      // });
      this.form.id = id;
      this.form.status = status
      updateUpdateUser(this.form).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.open = false;
        this.getList();
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateUpdateUser(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addUpdateUser(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除更新审核编号为"' + ids + '"的数据项？').then(function () {
        return delUpdateUser(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('wxuser/updateUser/export', {
        ...this.queryParams
      }, `updateUser_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
